from rest_framework import serializers

from questions.models import Label,Question
class LabelSerializer(serializers.ModelSerializer):
    '''标签序列化器类'''
    Authorization = serializers.CharField(label='JWT Token', read_only=True)
    class Meta:
        model=Label
        fields=('id', 'label_name','Authorization')


class QuestionsSerializer(serializers.ModelSerializer):
    '''问题序列化器类'''
    class Meta:
        model=Question
        fields='__all__'
        # exclude = ('content', 'thumbup', 'solve', 'updatetime')

    def create(self, validated_data):
        user = self.context['request'].user
        validated_data['user'] = user

        question = super().create(validated_data)
        return question

